from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-14 14:07:23.339942
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 14, Feb, 2022
Time: 14:07:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1192
Nobs: 567.000 HQIC: -48.5393
Log likelihood: 6686.27 FPE: 6.35183e-22
AIC: -48.8082 Det(Omega_mle): 5.42705e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.348511 0.068751 5.069 0.000
L1.Burgenland 0.106229 0.041831 2.539 0.011
L1.Kärnten -0.110963 0.021747 -5.103 0.000
L1.Niederösterreich 0.194057 0.087453 2.219 0.026
L1.Oberösterreich 0.128396 0.086255 1.489 0.137
L1.Salzburg 0.254825 0.044250 5.759 0.000
L1.Steiermark 0.035766 0.058359 0.613 0.540
L1.Tirol 0.100005 0.047079 2.124 0.034
L1.Vorarlberg -0.070972 0.041607 -1.706 0.088
L1.Wien 0.021345 0.076644 0.278 0.781
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054251 0.148594 0.365 0.715
L1.Burgenland -0.039766 0.090410 -0.440 0.660
L1.Kärnten 0.041168 0.047001 0.876 0.381
L1.Niederösterreich -0.200859 0.189014 -1.063 0.288
L1.Oberösterreich 0.458144 0.186425 2.458 0.014
L1.Salzburg 0.282200 0.095639 2.951 0.003
L1.Steiermark 0.113702 0.126133 0.901 0.367
L1.Tirol 0.304888 0.101753 2.996 0.003
L1.Vorarlberg 0.023510 0.089926 0.261 0.794
L1.Wien -0.027568 0.165653 -0.166 0.868
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198293 0.035030 5.661 0.000
L1.Burgenland 0.090037 0.021314 4.224 0.000
L1.Kärnten -0.007338 0.011080 -0.662 0.508
L1.Niederösterreich 0.235085 0.044559 5.276 0.000
L1.Oberösterreich 0.166137 0.043949 3.780 0.000
L1.Salzburg 0.039799 0.022546 1.765 0.078
L1.Steiermark 0.026372 0.029735 0.887 0.375
L1.Tirol 0.082061 0.023988 3.421 0.001
L1.Vorarlberg 0.055063 0.021200 2.597 0.009
L1.Wien 0.116328 0.039052 2.979 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121313 0.035105 3.456 0.001
L1.Burgenland 0.043660 0.021359 2.044 0.041
L1.Kärnten -0.013152 0.011104 -1.184 0.236
L1.Niederösterreich 0.170555 0.044655 3.819 0.000
L1.Oberösterreich 0.335668 0.044043 7.621 0.000
L1.Salzburg 0.100177 0.022595 4.434 0.000
L1.Steiermark 0.110265 0.029799 3.700 0.000
L1.Tirol 0.090333 0.024039 3.758 0.000
L1.Vorarlberg 0.060510 0.021245 2.848 0.004
L1.Wien -0.019458 0.039136 -0.497 0.619
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123382 0.066093 1.867 0.062
L1.Burgenland -0.047388 0.040213 -1.178 0.239
L1.Kärnten -0.045410 0.020906 -2.172 0.030
L1.Niederösterreich 0.139864 0.084071 1.664 0.096
L1.Oberösterreich 0.163145 0.082920 1.968 0.049
L1.Salzburg 0.284327 0.042539 6.684 0.000
L1.Steiermark 0.057522 0.056102 1.025 0.305
L1.Tirol 0.156473 0.045258 3.457 0.001
L1.Vorarlberg 0.095011 0.039998 2.375 0.018
L1.Wien 0.076151 0.073680 1.034 0.301
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080738 0.051575 1.565 0.117
L1.Burgenland 0.025215 0.031380 0.804 0.422
L1.Kärnten 0.053311 0.016313 3.268 0.001
L1.Niederösterreich 0.191359 0.065604 2.917 0.004
L1.Oberösterreich 0.328531 0.064705 5.077 0.000
L1.Salzburg 0.033832 0.033195 1.019 0.308
L1.Steiermark 0.005530 0.043779 0.126 0.899
L1.Tirol 0.120475 0.035317 3.411 0.001
L1.Vorarlberg 0.065543 0.031212 2.100 0.036
L1.Wien 0.097358 0.057495 1.693 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170094 0.062321 2.729 0.006
L1.Burgenland 0.004092 0.037918 0.108 0.914
L1.Kärnten -0.065888 0.019713 -3.342 0.001
L1.Niederösterreich -0.109346 0.079273 -1.379 0.168
L1.Oberösterreich 0.209796 0.078188 2.683 0.007
L1.Salzburg 0.053729 0.040111 1.340 0.180
L1.Steiermark 0.249366 0.052901 4.714 0.000
L1.Tirol 0.499730 0.042676 11.710 0.000
L1.Vorarlberg 0.064963 0.037715 1.722 0.085
L1.Wien -0.073390 0.069476 -1.056 0.291
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161493 0.069014 2.340 0.019
L1.Burgenland -0.005531 0.041991 -0.132 0.895
L1.Kärnten 0.062269 0.021830 2.853 0.004
L1.Niederösterreich 0.176298 0.087787 2.008 0.045
L1.Oberösterreich -0.061369 0.086585 -0.709 0.478
L1.Salzburg 0.205774 0.044419 4.633 0.000
L1.Steiermark 0.138158 0.058582 2.358 0.018
L1.Tirol 0.056211 0.047259 1.189 0.234
L1.Vorarlberg 0.143807 0.041766 3.443 0.001
L1.Wien 0.126444 0.076937 1.643 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393163 0.040478 9.713 0.000
L1.Burgenland -0.002911 0.024628 -0.118 0.906
L1.Kärnten -0.021384 0.012804 -1.670 0.095
L1.Niederösterreich 0.199938 0.051489 3.883 0.000
L1.Oberösterreich 0.230728 0.050784 4.543 0.000
L1.Salzburg 0.036715 0.026053 1.409 0.159
L1.Steiermark -0.017307 0.034360 -0.504 0.614
L1.Tirol 0.091231 0.027718 3.291 0.001
L1.Vorarlberg 0.051412 0.024497 2.099 0.036
L1.Wien 0.041368 0.045125 0.917 0.359
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035697 0.106291 0.167896 0.134267 0.095786 0.081754 0.029577 0.213249
Kärnten 0.035697 1.000000 -0.026085 0.132313 0.047358 0.085534 0.444127 -0.068314 0.090302
Niederösterreich 0.106291 -0.026085 1.000000 0.312256 0.123196 0.270515 0.065747 0.156786 0.284258
Oberösterreich 0.167896 0.132313 0.312256 1.000000 0.214386 0.293711 0.167916 0.134909 0.235637
Salzburg 0.134267 0.047358 0.123196 0.214386 1.000000 0.124225 0.091170 0.102897 0.126758
Steiermark 0.095786 0.085534 0.270515 0.293711 0.124225 1.000000 0.134260 0.105610 0.031374
Tirol 0.081754 0.444127 0.065747 0.167916 0.091170 0.134260 1.000000 0.062837 0.152203
Vorarlberg 0.029577 -0.068314 0.156786 0.134909 0.102897 0.105610 0.062837 1.000000 -0.003977
Wien 0.213249 0.090302 0.284258 0.235637 0.126758 0.031374 0.152203 -0.003977 1.000000